<?php

	/*
	*	file: pageStructUIMod.php
	*
	*	contents:	provides functions to make the structure of the page: Header, Body, Menu and contents area container
	*
	*	author: Lisa Pedrazzi, Federico Zanco (minor revs)
	*/



	/*
	* function checkIsSamePage($pageName)
	*
	* Input required:	$pageName: a name of a page, i.e. "index.php"
	*
	* Output:	return true if the input name is the same of the page in which is the user. Return false otherwise
	*
	* Author: Lisa Pedrazzi
	*/

	function checkIsSamePage($pageName) {
	
		$localPath = $_SERVER['PHP_SELF'];
		$localPage = str_replace('/', '', $localPath);
		
		if ($localPage==$pageName)
			return true;
		else
			return false;
	}



	/*
	* function showLogin()
	*
	* Input required:	$error: a string with error message to show
	*
	* Output:	show login page
	*
	* Author: Federico Zanco
	*/

	function showLogin($error) {
		echo "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"it\">

<head>
	<title>Login</title>
    
	<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
	<meta name=\"description\" content=\"Login\" />

	<link rel=\"stylesheet\" href=\"./style/screen.css\" type=\"text/css\" />
</head>
		
<body>

	<div id=\"container\">
	
		<!-- page header -->
		<div id=\"header\">
			<img src=\"./img/DoGe.jpg\" alt=\"DoGe - Gestore di Documenti \" />
			<div id=\"title\">
				<h1>Bell'Arte Tessile</h1>
			</div>
		</div>
		
		<br />
		
		<div id=\"login\">
			<div style=\"text-align: left;\">$error</div> <br />
			<form action=\"index.php\" enctype=\"multipart/form-data\" name=\"login\" method=\"POST\">
				<table id =\"insertTable\">
					<tr>
						<td><label for=\"username\">Nome utente: </label></td>
						<td><input type=\"text\" name=\"username\" id=\"username\" value=\"" . $_SESSION['username'] . "\" /></td>
					</tr>
					<tr>
						<td><label for=\"password\">Password: </label></td>
						<td><input type=\"password\" name=\"password\" id=\"username\" value=\"\" /></td>
					</tr>
					<tr>
						<td>
							<input name=\"Accedi\" type=\"submit\" value=\"Accedi\" />
						</td>
					</tr>
				</table>
			</form>
		</div>
		
		<!-- end of container -->
	</div>
	
</body>";

		exit();
	}



	/*
	* function showHeader($pageTitle, $pageDescription)
	*
	* Input required:	$pageTitle: the title of the page
	*					$pageDescription: the description of the content of the page
	*
	* Output:	shows to screen a piece of xhtml, the header of the page.
	*
	* Author: Lisa Pedrazzi
	*/

	function showHeader($pageTitle, $pageDescription) {
	
    	echo "
<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"it\">

<head>
	<title>$pageTitle</title>
    
	<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\" />
	<meta name=\"description\" content=\"$pageDescription\" />

	<link rel=\"stylesheet\" href=\"./style/screen.css\" type=\"text/css\" />
	
	

	<script language=\"JavaScript\" src=\"./js/getDate.js\"></script>
	<script language=\"JavaScript\" src=\"./js/getSubjectName.js\"></script>
	<script language=\"JavaScript\" src=\"./js/checkSubjects.js\"></script>
</head>

<body>

	<div id=\"container\">
		<!-- page header -->
		<div id=\"header\">
			<img src=\"./img/DoGe.jpg\" alt=\"DoGe - Gestore di Documenti \" />
			<div id=\"title\">
				<h1>Bell'Arte Tessile</h1>
			</div>
		</div>";
	}



	/*
	* function showMenu()
	*
	* Input required:	none
	*
	* Output:	shows to screen a piece of xhtml, the sidebar of the page (menu)
	*
	* Author: Lisa Pedrazzi
	*/

	function showMenu(){
    	echo "
		<!-- Page Sidebar containing all menus-->
		<div id=\"sidebar\">
			<!-- user actions-->
			<div id=\"actions\">
				<div id=\"welcome\">Benvenuto " . $_SESSION['username'] . "</div>
				<div id=\"logout\"><a href=\"login.php\" title=\"Esci dall'applicazione\">Esci</a></div>

				<ul>";
	
	//if user has insert authorization show Insert menu entry
	if ($_SESSION['insert_auth']) {
		if (checkIsSamePage("insert.php")) {
		echo "
					<li id=\"insert\"><strong>Inserisci</strong></li>";
		} else {
			echo "
					<li id=\"insert\"><a href=\"insert.php\" title=\"Inserimento di un nuovo documento\">Inserisci</a></li>";
		}
	}

	//if user has edit authorization show Modify menu entry
	if ($_SESSION['edit_auth']) {
		if (checkIsSamePage("modify.php")) {
			echo "
						<li id=\"modify\"><strong>Modifica</strong></li>";
		} else {
			echo "
					<li id=\"modify\"><a href=\"modify.php\" title=\"Modifica dei documenti\">Modifica</a></li>";
		}
	}
	
	//if user has search authorization show Search and Visualization menu entry
	if ($_SESSION['search_auth']) {
		if (checkIsSamePage("search.php")) {
			echo "
					<li id=\"search\"><strong>Ricerca e visualizza</strong></li>";
		} else {
			echo "
					<li id=\"search\"><a href=\"search.php\" title=\"Ricerca di un documento e visualizzazione\">Ricerca e<br />visualizza</a></li>";
		}
	}

	echo"
				</ul>
			</div>
			<!-- end of user actions-->
			<!-- user option-->
			
			<div id=\"options\">
				<!-- JS to resize the fonts-->
				<script type=\"text/javascript\">
				<!--
					if (document.getElementById) { 
						document.write('<div id=\"fontsize\">'); 
						document.write('Text\'s size:<br/>'); 
						document.write('<a class=\"fontsmall\" href=\"javascript:setFontSize(\'small\')\">Small</a> | ');
						document.write('<a class=\"fontmedium\" href=\"javascript:setFontSize(\'medium\')\">Medium</a> | ');
						document.write('<a class=\"fontlarge\" href=\"javascript:setFontSize(\'large\')\">Large</a>');
						document.write('</div>'); 
						document.getElementById(\"options\").style.display=\"block\";
					}
				
					function setFontSize(value) {
						theStyle = null;
						if (value == \"small\")
							theStyle = \"70%\";
						if (value == \"medium\") 
							theStyle = \"100%\";
						if (value == \"large\")
							theStyle = \"120%\";
						if (theStyle)
							document.getElementsByTagName(\"body\")[0].style.fontSize = theStyle;
					}
				// -->
				</script>
				<!-- end of JS to resize the fonts-->
			
				<!-- if someone doesn't have JS enabled...-->
				<noscript>
					<div class=\"fontsmall\">
						No resize texts options because your browser does not support Javascripts! <br />
						If you want to resize text use the option of your browser, if admits it.
					</div>
				</noscript>
			</div>
			<!-- end of user options-->
		</div>";
	}



	/*
	* function showContents($title, $errors, $text)
	*
	* Input required:	$title: screen-title of the page
	*					$errors: errors occourred (null string if there are no errors)
	*					$text: the content of the page
	*
	* Output:	shows to screen a piece of xhtml, the content of the page.
	*
	* Author: Lisa Pedrazzi
	*/

	function showContents($title, $errors, $text){
	
    	echo "
		<!-- Page Content -->
		<div id=\"contents\">
			<h2>$title</h2>";
		
    	if ($errors != "") {
	    echo "
			<div id=\"errors\">
				$errors
			</div>";
    	}
    
    	echo "
			<div class=\"text\">
				$text
			</div>
		</div>
		<!-- End of Page Content -->";
	
	}

	/*
	* function showFooter($lastModify)
	*
	* Input required:	$lastModify: the date of the last modify
	*
	* Output:	shows to screen a piece of xhtml, the bottom of the page.
	*
	* Author: Lisa Pedrazzi
	*/

	function showFooter($lastModify){
    	echo "
		<div id=\"info\">
			Realizzato da Diesel Team - Ultima modifica il: $lastModify
		</div>
		
		<!-- end of container -->
	</div>
</body>";
	}



	/*
	* function showErrorPage($error)
	*
	* Input required:	$error
	*
	* Output:	show a page with an errors notification area filled with $error
	*
	* Author: Federico Zanco
	*/	

	function showErrorPage($error) {
		global $lastRevs;
		/* Parameters for the pages*/

		//Header
		$pageTitle = "Errore interno";
		$pageDescription = "Si &egrave; verificato un errore!";

		//Content
		$title = "Errore!";
 
		//show a link to go back
		$text = "
				<a href=\"javascript:history.go(-1)\">Indietro</a>";

		showHeader($pageTitle, $pageDescription);
		showMenu();
		showContents($title, $error, $text);
		showFooter($lastRev);
		exit();
	}

?>